package com.apedad.example.controller;

import com.apedad.example.annotation.TargetDataSource;
import com.apedad.example.configuration.DataSourceDTO;
import com.apedad.example.service.UserInfoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *
 * @author : MagicCoder
 * @date : 2018-09-28 0028 17:38
 */
@RestController
@RequestMapping("/dataSwitch")
public class TestDataSwitch {
    private static final Logger LOG = Logger.getLogger(TestDataSwitch.class);

    @Resource(name = "userInfoService")
    private UserInfoService userInfoService;

    @Autowired
    DataSourceDTO dataSourceDTO;

    @RequestMapping("/getUserInfoFromDataBase")
    public Object getUserInfoFromDataBase(String dataSource){
        List result = userInfoService.listAll(dataSource);
        LOG.info(result);
        return result;
    }
    @RequestMapping("/getUserInfoFromDataNoAop")
    public Object getUserInfoFromDataNoAop(){
        List result = userInfoService.listAll();
        LOG.info(result);
        return result;
    }

    @RequestMapping("/getDataSourceProperties")
    public Object getDataSourceProperties(){
        LOG.info(dataSourceDTO.toString());
        return dataSourceDTO.toString();
    }

}
